import 'package:aone_common/controllers/login/login_logic.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:prototype/components/v_button.dart';
import 'package:prototype/components/v_text_field.dart';

Widget loginForm(BuildContext context) {

  final logic = LoginLogic.to;
  final state = LoginLogic.to.state;
  final validators = LoginLogic.to.validators;
  final formFields = LoginLogic.to.formFields;

  return SingleChildScrollView(
    padding: EdgeInsets.symmetric(horizontal: 20.0.h, vertical: 20.0.h),
    child: FormBuilder(
      key: state.formKey,
      child: Column(
        children: [
          VTextField(
            keyName: formFields.username,
            labelText: 'username'.tr,
            placeholder: 'username'.tr,
            initialValue: state.initialState?[formFields.username],
            validators: validators.username(),
          ),
          VTextField(
            keyName: formFields.password,
            labelText: 'password'.tr,
            placeholder: 'password'.tr,
            isPwd: true,
            initialValue: state.initialState?[formFields.password],
            hasPaddingBottom: false,
            textInputType: TextInputType.visiblePassword,
            validators: validators.password(),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              TextButton(
                onPressed: logic.enterTrialMode,
                child: Text('takeALook'.tr),
              ),
              TextButton(
                onPressed: logic.handleForgetPassword,
                child: Text('forget.password'.tr + '?'),
              )
            ],
          ),
          SizedBox(
            height: 60.h,
          ),
          VButton.primary(
            'login'.tr,
            onPressed: logic.handleSubmit,
          ),
        ],
      ),
    ),
  );
}
